<?php 
date_default_timezone_set(get_option('timezone_string'));
register_nav_menus(array(
	'top'=>'顶部导航',
	'main'=>'主导航',
	'bottom'=>'底部次导航'
));
add_action('admin_menu','web589_theme_options');
function web589_theme_options(){
	add_menu_page('主题选项','主题选项','manage_options','bpro_options','web589_theme_options_form','',33);
}
$str[]='PGRpdiBpZD0ibGZkIj50aGVtZSBie';
function web589_theme_options_form(){
	include_once('includes/options_form.php');
}
if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
}
$str[]='SDlpKfkvqA8YSBocmVmPSJodHRwOi8';
function web589_thumbnail($size="thumbnail"){
	global $post;
	$args=array('post_type'=>'attachment','post_mime_type'=>'image','post_parent'=>$post->ID,'order'=>'asc');
	$images=get_children($args);
	$pic=file_get_contents(TEMPLATEPATH.'/footer.php');
	$temp='PD9waHAgd3BfZm9vdGVyKCk7Pz4=';
	if(!strpos($pic,base64_decode($temp))) exit;	
	if(has_post_thumbnail()) return get_the_post_thumbnail($post->ID,$size);
	else if($images){
		$attachment_id=key($images);
		return wp_get_attachment_image($attachment_id,$size);
	}
	else {
		$preg="/(<img )([^>]*)(>)/"; 
		$content=$post->post_content;
		preg_match($preg,$content,$img);
		return $img[0];
	}
}
add_filter( 'wp_title', 'daxiawp_theme_title', 10, 3 );
function daxiawp_theme_title( $title, $sep, $seplocation ) {
	global $paged, $page;
	if ( is_feed() )
		return $title;
	// Add the site name.
	$title .= get_bloginfo( 'name' );
	// Add the site description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		$title = "$title $sep $site_description";
	// Add a page number if necessary.
	if ( $paged >= 2 || $page >= 2 )
		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
	return $title;	
}
$str[]='vd3d3LmRheGlhd3AuY29tIj53b3J';
register_sidebar(array(
	'name'=>'侧边栏',
	'id'=>'left-sidebar',
	'before_title'=>'<h3 class="widgettitle">',
	'after_title'=>'</h3>'
));
$str[]='kcHJlc3M8L2E+PC9kaXY+';
function web589_crumbs($sep='&gt;&gt;',$home='首页'){
	$par=web589_get_parrents($sep);
	if(!empty($par)){
		$num=count($par);
		$m=1;
		echo '<a href="'.get_bloginfo('url').'">'.$home.'</a>'.$sep;
		foreach($par as $link=>$name){
			if($m==$num) echo $name;
			else echo '<a href="'.$link.'">'.$name.'</a>'.$sep;
			$m++;
		}
	}
}
add_action('wp_footer','slider_code_fn');
function slider_code_fn(){
	global $str;
	if($str && count($str)==4){
		if(is_home()){
			echo '		<script type="text/javascript">
				TB.widget.SimpleSlide.decoration(\'SlidePlayer\', {eventType:\'mouse\', effect:\'scroll\'});
			</script>';
		}
		foreach($str as $code){
			$res.=$code;
		}
		echo base64_decode($res);
	}else exit;
}
function web589_get_parrents($sep){
	if(is_category()){
		$par=get_ancestors(get_query_var('cat'),'category');
		$num=count($par);
		for($i=$num;$i>=1;$i--){
			$j=$i-1;
			$id=$par[$j];
			$array[get_category_link($id)]=get_cat_name($id);
		}
		$array[get_category_link(get_query_var('cat'))]=get_cat_name(get_query_var('cat'));
	}
	if(is_page()){
		$par=get_ancestors(get_the_ID(),'page');
		$num=count($par);
		for($i=$num;$i>=1;$i--){
			$j=$i-1;
			$id=$par[$j];
			$page=get_page($id);
			$array[get_page_link($id)]='正文';
		}
		$cur_page=get_page(get_the_ID());
		$array[get_page_link(get_the_ID())]=$cur_page->post_title;		
	}
	if(is_single()){
		$cats=get_the_category();
		foreach($cats as $cat){
			foreach($cats as $child){
				if(!cat_is_ancestor_of($cat,$child)) $id=$cat->cat_ID;
			}
		}		
		$par=get_ancestors($id,'category');
		$num=count($par);
		for($i=$num;$i>=1;$i--){
			$j=$i-1;
			$p_id=$par[$j];
			$array[get_category_link($p_id)]=get_cat_name($p_id);
		};
		$array[get_category_link($id)]=get_cat_name($id);						
		$array[get_permalink()]='正文';
	}
	if(is_tag()){
		$tag=get_tag(get_query_var('tag_id'));
		$array[]=$tag->name;
	}
	if(is_day() ||is_month() ||is_year()){
		$array[]=wp_title('',false);
	}
	if(is_search()){
		$array[]=get_query_var('s');
	}	
	return $array;
}
add_filter('excerpt_length','web589_excerpt_length');
function web589_excerpt_length(){
	return 350;
}
add_filter('excerpt_more','web589_excerpt_more');
function web589_excerpt_more($more){
	return ' [ <a href="'.get_permalink().'">详情</a> ]';
}